#include "Widget.h"
#include "ui_Widget.h"
#include <QVBoxLayout>
#include <QHBoxLayout>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    // ui->setupUi(this);
    label = new QLabel;
    label->setMinimumSize(640,480);
    label->setScaledContents(true);
    label->setFocus();
    label->installEventFilter(this);//安装一个过滤器,所有信号都先经过this再到label

    leftBtn = new QPushButton("<");
    rightBtn = new QPushButton(">");
    openBtn = new QPushButton("Open");
    //先水平布局
    QHBoxLayout *hbox = new QHBoxLayout;

    hbox->addStretch();//在左侧按钮加一个弹簧
    hbox->addWidget(leftBtn);
    hbox->addWidget(openBtn);
    hbox->addWidget(rightBtn);
    hbox->addStretch();//在右侧按钮加一个弹簧
    //再垂直布局
    QVBoxLayout *vbox = new QVBoxLayout;
    vbox->addWidget(label);
    vbox->addLayout(hbox);

    this->setLayout(vbox);


    connect(openBtn,SIGNAL(clicked(bool)),this, SLOT(openFiles()));
    connect(leftBtn,SIGNAL(clicked(bool)),this,SLOT(showLeft()));
    connect(rightBtn,SIGNAL(clicked(bool)),this,SLOT(showRight()));
}

Widget::~Widget()
{
    delete ui;
}
